
// Code for message action to add an issue in Zoho Projects

form = Map();
description = message.get("text");
option = List();
inputs = List();
res = invokeurl
[
	url :"https://projectsapi.zoho.com/restapi/portals/"
	type :GET
	connection:"ENTER YOUR CONNECTION NAME"
];
if(!res.get("portals").isEmpty())
{
	portals = res.get("portals");
	for each  portal in portals
	{
		entry = Map();
		entry.put("label",portal.get("name"));
		entry.put("value",portal.get("id_string"));
		option.add(entry);
	}
	inputs.add({"type":"select","name":"portals","label":"Portals","trigger_on_change":true,"hint":"All projects from the default portal are listed here","placeholder":"Choose a portal","mandatory":true,"options":option});
	inputs.add({"type":"text","name":"title","label":"Title","hint":"Enter the issue name","placeholder":"Ex: Ryan's laptop isn't working","mandatory":true,"value":""});
	inputs.add({"type":"textarea","name":"description","label":"Description","hint":"Briefly describe the issue","max_length":1000,"placeholder":"IT-Support: Requests on device maintenance and software installation","mandatory":false,"value":description});
	form = {"type":"form","title":"Add Issue","hint":"Select the project into which you want to add the issue.","name":"add","version":1,"button_label":"Add","actions":{"submit":{"type":"invoke.function","name":"addissue"}},"inputs":inputs};
}
else
{
	return {"text":"Your account does not have any portals.\nDo try again after creating portals."};
}
return form;
